<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache"/>   
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate"/>   
<meta http-equiv="expires" content="0"/>
<title>发送站内信</title>

<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="../js/application/message.js?201808042"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>
<script type="text/javascript" src="../editor/kindeditor.js"></script>

</head>
<body>
<style>
.tablelist td {max-width: 50px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
.addbtn span {float: left;margin-left: 10px;margin-right: 5px;margin-top: 5px;}
.addbtn{background: url(../images/toolbg.gif) repeat-x;line-height: 33px;height: 33px;border: solid 1px #d3dbde;float: left;padding-right: 10px;margin-right: 5px;border-radius: 3px;behavior: url(js/pie.htc);cursor: pointer;color:#000;font-weight:normal}
</style>
<div class="incList">	
    <div class="place" name="msgList">
        <span>位置：</span>
        <ul class="placeul">
            <li><a href="#">消息通知</a></li>
            <li><a href="#">发送站内信</a></li>
        </ul>
    </div> 
    <div class="formbody" name="msgList">
        <div class="tools">
            <ul class="seachform">   
				<li class="click addbtn" id="add"><span><img src="../images/t01.png"></span>添加</li>			
                <li>
                	<label>目标用户区域</label>
                    <div class="vocation">
                        <select class="tlselect" name="areaSelect" id="searchArea">
                            <option value="0" selected>请选择</option>
                        </select>
                    </div>
				</li>
				<li>
                	<label>目标用户类型</label>
                    <div class="vocation">
                        <select class="tlselect" name="areaSelect" id="searchType">
                            <option value="0" selected>全部会员</option>
                            <option value="-1">特定会员</option>
                            <option value="-2">指定客户</option>
                        </select>
                    </div>
				</li>
                <li>
                    <label>标题</label>
                    <input type="text" name="title" class="tlinput"  id="searchTitle"/>
                </li>
                <li><label>&nbsp;</label><input name="btnSerch" onclick="search();" type="button" class="scbtn" value="搜索"/></li>
            </ul>
        </div>
        <div id="usual1" class="usual">     
            <div id="tab2" class="tabson">    
                <table class="tablelist">
                    <thead>
                        <tr>
                        	<th></th>
                            <th>标题</th>
                            <th>内容</th>
                            <th>目标用户区域</th>
                            <th>创建人</th>
                            <th>发送时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="userTable"></tbody>
                </table>
                <div class="pagin">
                    <div class="message">共<i id="totalRow" class="blue">0</i>条记录，每页<i id="pageSize" class="blue">2&nbsp;</i>条记录，当前显示第&nbsp;<i id="currentPage" class="blue">2&nbsp;</i>页</div>
                    <ul class="paginList" ></ul>
                </div>
            </div>
        </div>   
    </div>
    
	
	<div class="place" name="AddMsg" style="display: none">
	    <span>位置：</span>
	    <ul class="placeul">
            <li><a href="#">消息通知</a></li>
            <li><a href="#">发送站内信</a></li>
	    <li><a href="#" id="addBtn">添加</a></li>
	    </ul>
	</div>
	    
	<div class="formbody" name="AddMsg" style="display: none">
	    
	    <div class="formtitle"><span>新建站内信</span></div>
	    
	    <ul class="forminfo" style="display: table;width:670px">
	    	<li>
		    	<label style="font-size:16px;margin-top:-5px;">空间</label>
		    	<p style="font-size:16px;">
		    	<select class="tlselect" name="addAreaSelect" id="addArea">
                    <option value="0" selected>请选择</option>
                </select>
				</p>
				<div class="divLine"></div>
			</li>
		    <li>
			<label style="font-size:16px;margin-top:0px;"><font color="red">*</font>目标人群</label>
				
				<label class="radio-inline"><input name="addtype" onclick="addTypeChange()" type="radio" value="1" checked="checked" />广播(所有人)</label>
				<label class="radio-inline"><input name="addtype" onclick="addTypeChange()" id="addType" type="radio" value="2" />系统管理员</label>
				<label class="radio-inline"><input name="addtype" onclick="addTypeChange()" id="addType" type="radio" value="3" />特定用户</label>
				<label class="radio-inline"><input name="addtype" onclick="addTypeChange()" id="addType" type="radio" value="4" />指定客户</label>
				</cite>	
			</li>
			
		    <li id="addUserType_li" style="display:none">
		    	<label style="font-size:16px;margin-top:-5px;">管理员角色</label>
		    	<p style="font-size:16px;" id="rolelist"></p>
				<div class="divLine"></div>
			</li>
		    <li id="addUserMobile_li" style="display:none">
		    	<label style="font-size:16px;margin-top:-5px;">用户手机号</label>
		    	<p style="font-size:16px;"><input type="text" name="addUserMobile" class="tlinput" id="addUserMobile"></p>
				<div class="divLine"></div>
			</li>
		    
		    <li  id="addUserClient_li"  style="display:none">
		    	<label style="font-size:16px;margin-top:-5px;">选择客户</label>
		    	<p style="font-size:16px;">
		    	<select class="tlselect" name="addUserSelect" id="addUserClient">
                    <option value="0" selected>请选择</option>
                </select>
</p>
				<div class="divLine"></div>
			</li>


	    </ul>
       <div class="formtitle"><span>站内信基本信息</span></div>
        <ul class="forminfo">
        	<li >
		    	<label style="font-size:16px;margin-top:-5px;"><font color="red">*</font>标题</label>
		    	<p style="font-size:16px;"><input type="text" name="addtitle" id="addTitle" class="tlinput" style="width:650px"></p>
				<div class="divLine"></div>
			</li>
        	<li >
		    	<label style="font-size:16px;margin-top:-5px;"><font color="red">*</font>内容</label>
		    	<p style="font-size:16px;">
		    	<textarea name='addcontent' id="addContent" formParameter="client" placeholder="请输入内容" cols="" rows="" class="langtext" style="width:650px"></textarea></p>
				<div class="divLine"></div>
			</li>
        	<li>
		    	<label>&nbsp;</label>
		    	<input name="btnSave"  id="btnSave"  type="button" class="btn" value="确定"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		    	<input name="btnCancle"  id="btnCancle"  type="button" class="btn" value="取消"/>
		    </li>
        </ul>
    </div>
    <style>
    ul#msgViewInfo li, ul#msgViewInfo li label{margin-top:-5px;font-size:16px;}</style>
	<div class="place" name="viewInfo" style="display: none">
	    <span>位置：</span>
	    <ul class="placeul">
            <li><a href="#">消息通知</a></li>
            <li><a href="/euc/page/message/messagelist.html">站内信列表</a></li>
	    <li><a href="#">详情</a></li>
	    </ul>
	</div>
		<div class="formbody" name="viewInfo" style="display: none">
		    <div class="formtitle"><span>详情</span></div>
		     <ul class="forminfo" id="msgViewInfo" style="display: table;"></ul>
		     <div id="btnViewCancle"  class="btn" >关闭</div>
		    </div>
	    </div>
	    
<script>
$(function(){
	$("#add").click(function(){
		$("DIV[name='msgList']").hide();
		$("DIV[name='AddMsg']").show();	
		$("DIV[name='viewInfo']").hide();	
	})
	$("#btnCancle,#btnViewCancle").click(function(){
		$("DIV[name='msgList']").show();
		$("DIV[name='AddMsg']").hide();	
		$("DIV[name='viewInfo']").hide();	
	})
	

			
			$("#btnSave").click(function(){
				$title=$.trim($("#addTitle").val());
				if(!$title){
					alert("站内信标题不能为空");return;
				}
				$content=$.trim($("#addContent").val());
				if(!$content){
					alert("站内信内容不能为空");return;
				}
				$addArea=$("#addArea").val();
				if(!$addArea||$addArea==0){
					alert("请选择空间");return;
				}

				$targetType = parseInt($("input[name='addtype']:checked").val());
				switch($targetType){
					case 1:
						$area=$("#addArea").val();
						targetInfo="";break;
					case 2:
						$area=0;
						targetInfo=getCheckedValue();break;
					case 3:
						$area=$("#addArea").val();
						targetInfo=$("#addUserMobile").val();break;
					case 4:
						$area=$("#addArea").val();
						$Client=$("#addUserClient").val();
						targetInfo='';
						if(!$area) $area = 0;
						if(!$Client) {
							$Client=0;
						}
						targetInfo= $area+'|'+$Client;
						$area=0;
						break;
					default:
				}
                var reg = new RegExp( "\"" , "g" )
                var newstr = $content.replace( reg , "'" );
                newstr = encodeURI(newstr);
				var theData = '{"data":{"createPerson":"admin","title":"'+$title+'","content":"'+newstr+'","targetType":'+$targetType+',"targetInfo":"'+targetInfo+'","userAreaId":'+$area+',"userType":0,"space":0,"target":0}}'
                //theData = encodeURI(theData);
				$.ajax({
			        url: '/euc/onlineops/msg/add',
			        data: theData,
			        beforeSend: function(request) {
			        	var accessToken = localStorage.getItem('accessToken');
			            request.setRequestHeader("accessToken",accessToken );
			        },
			        dataType: 'JSON',
			        async: true,
			        contentType:'application/json;charset=utf-8',
			        type: 'POST',
			        success: function (data, textStatus, response) {
			        	if(data.status==0){
			        		alert("发送成功！");
			        		window.location.reload();
			        	}else{
			        		alert(data.message);
			        	}
			        },
			        error: function () {
			        	console.log("error");
			        }
			    });
				
		});
	
		
});

function getCheckedValue() {
	var str = "";
	$("input:checkbox[name='addUserType']:checked").each(function(i) {
	var val = $(this).val();
	if(str===""){
		str = val ;
	}else{
		str = str+ "|" + val ;
	}

	});
	return str;
}
function addTypeChange(){
	$type =$("#addType:checked").val();
	
	if($type==2){
		$("#addUserType_li").show();
	}else{
		$("#addUserType_li").hide();
	}
	if($type==3){
		$("#addUserMobile_li").show();
	}else{
		$("#addUserMobile_li").hide();
	}
	if($type==4){
		$("#addUserSpace_li").show();
		$("#addUserClient_li").show();
	}else{
		$("#addUserSpace_li").hide();
		$("#addUserClient_li").hide();
	}
}
function addRole(){
	$("INPUT[name='roleName']").val("");
	$("INPUT[type=checkbox]").prop({checked:false});	
	$("#roleOperator").html("添加");
	$("#btnSave").unbind();
	$("#btnSave").click(saveRole);
	$("DIV[name='roleShowList']").hide();
	$("DIV[name='roleAddForm']").show();	
}



</script>
	<script>
	var editor1;
KindEditor.ready(function(K) {
		editor1 = K.create('textarea[name="addcontent"]', {
			//cssPath : '../edit/plugins/code/prettify.css',
			allowFileManager : true,
            uploadJson : '../editor/jsp/upload_json.jsp',
            fileManagerJson : '../editor/jsp/file_manager_json.jsp',
			afterCreate : function() {
				var self = this;	
			},
			afterBlur: function(){this.sync();}
			,
			pasteType : 2,  
            filterMode: false
			
		});
		editor1.sync();
})

</script>
	
</div>
</body>
</html>
